#include "keyboard.h"k
#include "usb_device.h"
#include "usbd_core.h"
#include "usbd_desc.h"
#include "usbd_customhid.h"
#include "usbd_custom_hid_if.h"

uint8_t report_ctrl_on0[8] = {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
uint8_t report_ctrl_on1[12] = {0x08, 0x00, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
uint8_t report_ctrl_off0[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
uint8_t report_ctrl_off1[12] = {0x08, 0x00, 0x1d, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

uint8_t report_ctrl_c_on0[8] = {0x01, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00};
uint8_t report_ctrl_c_on1[12] = {0x08, 0x00, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
uint8_t report_ctrl_c_off0[8] = {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
uint8_t report_ctrl_c_off1[12] = {0x08, 0x00, 0x2e, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

uint8_t report_ctrl_v_on0[8] = {0x01, 0x00, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00};
uint8_t report_ctrl_v_on1[12] = {0x08, 0x00, 0x2f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
uint8_t report_ctrl_v_off0[8] = {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
uint8_t report_ctrl_v_off1[12] = {0x08, 0x00, 0x2f, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

uint8_t report_c_on0[8] = {0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00};
uint8_t report_c_on1[12] = {0x08, 0x00, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
uint8_t report_c_off0[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
uint8_t report_c_off1[12] = {0x08, 0x00, 0x2e, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

uint8_t report_v_on0[8] = {0x00, 0x00, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00};
uint8_t report_v_on1[12] = {0x08, 0x00, 0x2f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
uint8_t report_v_off0[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
uint8_t report_v_off1[12] = {0x08, 0x00, 0x2f, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
extern USBD_HandleTypeDef hUsbDeviceFS;
void key_task()
{
    if (CTRL == 0)
    {
        HAL_Delay(10);
        while (CTRL == 0)
        {
            USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, report_ctrl_on0, 8);
            USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, report_ctrl_on1, 12);
            HAL_Delay(150);
            if (C == 0)
            {
                HAL_Delay(10);
                while (C == 0)
                {
                    USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, report_ctrl_c_on0, 8);
                    USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, report_ctrl_c_on1, 12);
                    HAL_Delay(150);
                }
                USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, report_ctrl_c_off0, 8);
                USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, report_ctrl_c_off1, 12);
            }
            else if (V == 0)
            {
                HAL_Delay(10);
                while (V == 0)
                {
                    USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, report_ctrl_v_on0, 8);
                    USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, report_ctrl_v_on1, 12);
                    HAL_Delay(150);
                }
                USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, report_ctrl_v_off0, 8);
                USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, report_ctrl_v_off1, 12);
            }
        }
        USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, report_ctrl_off0, 8);
        USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, report_ctrl_off1, 12);
    }
    else if (C == 0)
    {
        HAL_Delay(10);
        while (C == 0)
        {
            USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, report_c_on0, 8);
            USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, report_c_on1, 12);
            HAL_Delay(150);
        }
        USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, report_c_off0, 8);
        USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, report_c_off1, 12);
    }
    else if (V == 0)
    {
        HAL_Delay(10);
        while (V == 0)
        {
            USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, report_v_on0, 8);
            USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, report_v_on1, 12);
            HAL_Delay(150);
        }
        USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, report_v_off0, 8);
        USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, report_v_off1, 12);
    }
}
